package com.javaweb.util.core;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;

/**
 * 系统工具类
 * @author tank2140896
 */
public class SystemUtil {
	
	//小于等于JDK8不支持：public static final java.lang.Runtime.Version JDK_VERSION = Runtime.version();
    //系统配置参数获取：Properties properties = System.getProperties();properties.list(System.out);
	
    /**
     * 判断是不是linux系统
     * @return boolean 是不是linux系统（true：是；false：不是）
     */
	public static boolean isLinux() {
        return System.getProperty("os.name").toLowerCase().contains("linux");
    }
    
	/**
	 * 获取本地mac地址
	 * <p>
	 * InetAddress inetAddress = InetAddress.getLocalHost();
	 * 
	 * @param inetAddress 网络地址
	 * @return String mac地址
	 * @throws SocketException SocketException
	 */
	public static String getLocalMac(InetAddress inetAddress) throws SocketException {
        byte[] mac = NetworkInterface.getByInetAddress(inetAddress).getHardwareAddress();
        StringBuffer stringBuffer = new StringBuffer();
        for(int i=0;i<mac.length;i++) {
            if(i!=0) {
            	stringBuffer.append("-");
            }
            int temp = mac[i]&0xFF;
            String str = Integer.toHexString(temp);
            if(str.length()==1) {
            	stringBuffer.append("0"+str);
            } else {
            	stringBuffer.append(str);
            }
        }
        return stringBuffer.toString();
    }
    
}
